<template>
    <div>
        <!-- 表格 -->
        <el-table :data="getMenu" border style="width: 100%" lazy :load="load" row-key="id"
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
            <el-table-column prop="id" label="菜单编号" width="80">
            </el-table-column>
            <el-table-column prop="title" label="菜单名称" width="120">
            </el-table-column>
            <el-table-column prop="pid" label="上级菜单" width="100">
            </el-table-column>
            <el-table-column label="菜单图标" width="100">
                <template slot-scope="item">
                    <div>
                        <i :class="item.row.icon"></i>
                     </div>
                </template>
            </el-table-column>
            <el-table-column prop="url" label="菜单地址" width="100">
            </el-table-column>
            <el-table-column label="状态" width="100">
                <template slot-scope="item">
                    <div>
                        <el-button type="success" plain size="mini">{{ item.row.status == 1 ? "启用" : "禁用" }}</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="220">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" icon="el-icon-edit" plain size="mini" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" icon="el-icon-delete" plain size="mini"
                            @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>

            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import { menudelete } from '../../request/api'
import { mapGetters, mapActions } from 'vuex';
export default {
    data() {
        return {
            icon: []
        }
    },
    methods: {
        // 删除菜单
        del(id) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                menudelete({id})
                .then(res=>{
                    if(res.code == 200){
                        this.$message.success(res.msg)
                        // 删除成功重新调用接口
                        this.getMenuList()
                    }
                })  
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        // 编辑菜单
        edit(id) {//告诉父元素打开弹窗
            this.$emit('edit',id)
        },

        load(tree, treeNode, resolve) {
            setTimeout(() => {
                resolve([

                ])
            }, 1000)
        },
        ...mapActions({
            getMenuList: 'menu/GetMenuInfo'
        })
    },
    mounted() {
        // console.log(this.$store);
        this.getMenuList()
    },
    computed: {
        ...mapGetters({
            getMenu: 'menu/getMenu'
        })
    },

    components: {}
}
</script>
<style scoped></style>